/*
Copyright (c) 2009, Luke Berndt
All rights reserved.
 
 * More Information: http://www.tagflo.com

Redistribution and use in source and binary forms, with or without modification, are permitted 
provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this list of conditions 
  and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice, this list of conditions 
  and the following disclaimer in the documentation and/or other materials provided with the distribution.

* Neither the name of RoboTastic Software nor the names of its contributors may be used to endorse or 
  promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED 
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
POSSIBILITY OF SUCH DAMAGE.
*/


using System;
using System.Collections.Generic;
using System.Text;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Media;
using System.IO;

namespace TagFlo
{
    public class PathConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter,
        System.Globalization.CultureInfo culture)
        {
            HierarchyPath hPath = (HierarchyPath)value;
            if (hPath == null)
            {
                return "";
            }
            if (hPath.Path.IsRoot != 0)
            {
                DirectoryInfo d = new DirectoryInfo(hPath.Path.FullPath);
                return "..\\" + d.Name;
            }
            else
            {
                DirectoryInfo d = new DirectoryInfo(hPath.Path.FullPath);
                return "\\" + d.Name;
            }

        }

        public object ConvertBack(object value, Type targetType, object parameter,
        System.Globalization.CultureInfo culture)
        {
            throw new NotSupportedException();
        }
    }

    public class FocalLengthConverter : IValueConverter
    {
        public object Convert(object value)
        {
            return Convert(value, null, null, null);
        }

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value != null)
            {

                
                if (value.ToString() == "-1")
                {
                    return "Undefined";
                }
                else
                {
                    return String.Format("{0}mm", value);
                }
            }
            else
            {
                return "Undefined";
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }

    public class LensApertureConverter : IValueConverter
    {
        public object Convert(object value)
        {
            return Convert(value, null, null, null);
        }

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value != null)
            {
               
                if (value.ToString() == "-1")
                {
                    return "Undefined";
                }
                else
                {
                    return String.Format("F{0:##.0}", value);
                }
            }
            else
            {
                return "Undefined";
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }

    }

    public class ExposureTimeConverter : IValueConverter
    {
        public object Convert(object value)
        {
            return Convert(value, null, null, null);
        }

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value != null)
            {

                if (value.ToString() == "-1")
                {
                    return "Undefined";
                }
                else
                {
                    return String.Format("1/{0}", value);
                }
            }
            else
            {
                return "Undefined";
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }

    }

    public class IsoSpeedConverter : IValueConverter
    {
        public object Convert(object value)
        {
            return Convert(value, null, null, null);
        }

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value != null)
            {
                if (value.ToString() == "-1")
                {
                    return "Undefined";
                }
                else
                {
                    return String.Format("{0} ISO", value);
                }
            }
            else
            {
                return "Undefined";
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }

    }



    public class DateConverter : IValueConverter
    {
        public object Convert(object value)
        {
            return Convert(value, null, null, null);
        }

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value != null)
            {
                DateTime date = (DateTime)value;


                return date.ToString("dd MMMM yyyy");
                
            }
            else
            {
                return "";
            }

        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }

    }



    public class RatingConverter : IValueConverter
    {
        public object Convert(object value)
        {
            return Convert(value, null, null, null);
        }
        
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value != null)
            {
                int numValue;
                if (value.GetType() == typeof(string))
                {
                    numValue = int.Parse(value as string);
                }
                else
                {
                    string s = value.GetType().ToString();

                    numValue = System.Convert.ToInt16(value);
                }
                if (numValue < 1)
                {
                    return "Unrated";
                }
                else
                {
                    return String.Format("{0} Stars", numValue);
                }
            }
            else
            {
                return "Unrated";
            }

        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }

    }

    public class CameraModelConverter : IValueConverter
    {
        public object Convert(object value)
        {
            return Convert(value, null, null, null);
        }

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value != null)
            {
                if (value.GetType() == typeof(string))
                {

                    if ((value as string) == "")
                    {
                        return "Undefined";
                    }
                    else
                    {
                        return value;
                    }
                }
                return "Undefined";
                   
            }
            else
            {
                return "Unrated";
            }

        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }

    }

    public class WhiteBalanceConverter : IValueConverter
    {
        public object Convert(object value)
        {
            return Convert(value, null, null, null);
        }

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value != null)
            {
                int numValue = (int)value;

                switch (numValue)
                {
                    case 1: return "Daylight";
                    case 2: return "Fluorescent";
                    case 3: return "Tungsten";
                    case 10: return "Flash";
                    case 17: return "StandardLightA";
                    case 18: return "StandardLightB";
                    case 19: return "StandardLightC";
                    case 20: return "D55";
                    case 21: return "D65";
                    case 22: return "D75";
                    case 255: return "Other";
                    default: return "Unknown";
                }
            }
            else
            {
                return "Unknown";
            }


        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }

    }

    public class ExposureModeConverter : IValueConverter
    {
        public object Convert(object value)
        {
            return Convert(value, null, null, null);
        }

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value != null)
            {
                int numValue = (int)value;
                switch (numValue)
                {
                    case 1: return "Manual";
                    case 2: return "NormalProgram";
                    case 3: return "AperturePriority";
                    case 4: return "ShutterPriority";
                    case 5: return "LowSpeedMode";
                    case 6: return "HighSpeedMode";
                    case 7: return "PortraitMode";
                    case 8: return "LandscapeMode";
                    default: return "Unknown";
                }

            }
            else
            {
                return "Unknown";
            }

        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }

    }


    public class SelectionTagConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            int numValue = (int)value;
  
            if (numValue < 4)
            { return "Some"; }
            else
            { return "All"; }
            

        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
   
    }

    public class RankColorConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {

            try
            {

                int numValue = (int)value;
               
                numValue = numValue % 10;
                switch (numValue)
                {
                    case 1:
                        return System.Windows.Media.Brushes.Thistle;
                    case 2:
                        return System.Windows.Media.Brushes.LightSalmon;
                    case 3:
                        return System.Windows.Media.Brushes.SkyBlue;
                    case 4:
                        return System.Windows.Media.Brushes.LightSteelBlue;
                    case 5:
                        return System.Windows.Media.Brushes.GreenYellow;
                    case 6:
                        return System.Windows.Media.Brushes.LightSkyBlue;
                    case 7:
                        return System.Windows.Media.Brushes.Salmon;
                    case 8:
                        return System.Windows.Media.Brushes.SteelBlue;
                    case 9:
                        return System.Windows.Media.Brushes.Gold;
                       case 0:
                        return System.Windows.Media.Brushes.Tomato;
                 


                }

                SolidColorBrush temp = new SolidColorBrush(Color.FromRgb(175,175,(byte) numValue));
               return temp;
           
            }
            catch 
            {
                return System.Windows.Media.Brushes.White;
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }
}
